﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:controls="clr-namespace:Reporter.Controls" 
    xmlns:converters="clr-namespace:Reporter.Converters" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
	xmlns:Reporter_Data="clr-namespace:Reporter.Data" 
    xmlns:rcl="clr-namespace:ReporterControlLibrary;assembly=ReporterControlLibrary"
	mc:Ignorable="d"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:UIHelpers="clr-namespace:ReporterControlLibrary.UIHelpers;assembly=ReporterControlLibrary" 
    x:Class="Reporter.Controls.ProjectUserControl"
	x:Name="UserControl"
	d:DesignWidth="882" d:DesignHeight="589.502">

    <UserControl.Resources>

        <converters:IntToVisibilityConverter SourceValue="0" MatchValue="Visible" MisMatchValue="Collapsed" x:Key="ItemsCountToVisibilityConverter" />
        <converters:ImportNotebookMultiConverter x:Key="ImportNotebookMultiConverter"/>

        <DataTemplate x:Key="ReportInfoModelTemplate">
            <controls:ProjectTplListBoxItem />
        </DataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid Margin="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="322"/>
            </Grid.ColumnDefinitions>
            <TabControl x:Name="ProjectTab" Background="#FFF9F9F9" BorderBrush="#FF8C8E94" Style="{DynamicResource ProjectInfoTabControl}" TabStripPlacement="Left">
                <TabItem Header="Templates">
                    <Grid Margin="0" VerticalAlignment="Top" MinHeight="400">
                        <Border Style="{DynamicResource ApplicationOuterPanelBorderStyle}">
                            <Border Style="{DynamicResource ApplicationPanelBorderStyle}">
                                <Border Style="{DynamicResource ApplicationInnerPanelBorderStyle}">
                            		<Grid>
                                        <ListBox x:Name="reportInfo_lb" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="{x:Null}"  ItemTemplate="{DynamicResource ReportInfoModelTemplate}" ItemsSource="{Binding ReportInfos, Mode=OneWay}" ItemContainerStyle="{DynamicResource ReportInfoListBoxItem}" Margin="0"/>
                            			<Button x:Name="AddTemplate_btn" Content="Add Template" Padding="5,5,7,5" VerticalAlignment="Top" Visibility="{Binding Items.Count, Converter={StaticResource ItemsCountToVisibilityConverter}, ElementName=reportInfo_lb}" HorizontalAlignment="Left" Margin="10,10,0,0">
                            				<i:Interaction.Triggers>
                            					<i:EventTrigger EventName="Click">
                            						<i:InvokeCommandAction Command="{Binding AddProjectTemplateCommmand, Mode=OneWay, Source={StaticResource ApplicationManager}}"  CommandParameter="{Binding Mode=OneWay}"/>
                            					</i:EventTrigger>
                            				</i:Interaction.Triggers>
                            			</Button>
                            		</Grid>
                            	</Border>
                            </Border>
                        </Border>
                    </Grid>
                </TabItem>
                <TabItem Header="Preferences" Background="{DynamicResource ApplicationPanelBackgroundBrush}" Foreground="White">
                    <Border Style="{DynamicResource ApplicationOuterPanelBorderStyle}">
                        <Border Style="{DynamicResource ApplicationPanelBorderStyle}">
                            <Border Style="{DynamicResource ApplicationInnerPanelBorderStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="5"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="28"/>
                                        <RowDefinition Height="41"/>
                                        <RowDefinition Height="15"/>
                                        <RowDefinition Height="32"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="81.04"/>
                                        <ColumnDefinition/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Margin="0,0,4,0" Grid.Row="2" VerticalAlignment="Center" Text="Date format" Style="{DynamicResource FormLabelStyle}"/>
                                    <CheckBox Content="Suspend generation process on error" d:LayoutOverrides="Width" Grid.Row="6" Grid.ColumnSpan="2" VerticalAlignment="Center" Margin="6,0,0,0" IsChecked="{Binding ProjectPreferences.SuspendOnError, Mode=TwoWay}" Style="{DynamicResource FormCheckBoxStyle}"/>
                                    <CheckBox Content="Show warnings" d:LayoutOverrides="Width" Grid.Row="7" Grid.ColumnSpan="2" VerticalAlignment="Center" Margin="6,0,0,0" IsChecked="{Binding ProjectPreferences.ShowWarnings, Mode=TwoWay}" Style="{DynamicResource FormCheckBoxStyle}"/>
                                    <TextBox TextWrapping="Wrap" HorizontalAlignment="Left" Grid.Column="1" Margin="5,0,0,0" Width="250" Grid.Row="1" VerticalAlignment="Center" Text="{Binding Name, Mode=TwoWay}"/>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Margin="0,0,4,0" Grid.Row="1" VerticalAlignment="Center" Text="Project name" Style="{DynamicResource FormLabelStyle}"/>
                                    <StackPanel Grid.Column="1" Orientation="Horizontal" Grid.Row="2" Margin="5,0,185.96,0" d:LayoutOverrides="Width">
                                        <ComboBox x:Name="DateFormat_cb" ItemsSource="{x:Static Reporter_Data:AppData.DateFormats}" VerticalAlignment="Center" Width="200" HorizontalAlignment="Left" SelectedIndex="1" IsEditable="True" Text="{Binding ProjectPreferences.DateFormat, Mode=TwoWay}" IsSynchronizedWithCurrentItem="False"/>
                                        <TextBlock x:Name="SampleDate_tb" Text="{Binding Text, Converter={StaticResource DateFormatConverter}, ElementName=DateFormat_cb}" Foreground="{DynamicResource LightBrush}" VerticalAlignment="Center" Margin="5,0,0,0"/>
                                    </StackPanel>
                                    <Button x:Name="deleteProjectButton" Content="Delete project"  Grid.Row="8" ToolTip="Delete this project" Height="25" HorizontalAlignment="Left" Margin="7,6.312,0,6.311" Padding="5,1" d:LayoutOverrides="GridBox, VerticalMargin" Grid.ColumnSpan="2" >
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <i:InvokeCommandAction Command="{Binding DeleteProjectCommmand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </Button>
                                    <TextBox x:Name="publishUrl" TextWrapping="Wrap" Grid.Column="1" Margin="5,0,10,0" Grid.Row="3" VerticalAlignment="Center" Text="{Binding ProjectPreferences.PublishUrl}"/>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Margin="0,0,4,0" Grid.Row="3" VerticalAlignment="Center" Text="Publish Url" Style="{DynamicResource FormLabelStyle}"/>
                                    <TextBox TextWrapping="Wrap" HorizontalAlignment="Left" Grid.Column="1" Margin="5,0,0,0" Width="250" Grid.Row="4" VerticalAlignment="Center" Text="{Binding ProjectPreferences.Login}"/>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Margin="0,0,4,0" Grid.Row="4" VerticalAlignment="Center" Text="Login" Style="{DynamicResource FormLabelStyle}"/>
                                    <PasswordBox x:Name="passwordBox" UIHelpers:PasswordBoxAssistant.BindPassword="True" UIHelpers:PasswordBoxAssistant.BoundPassword="{Binding Path=ProjectPreferences.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" d:LayoutOverrides="Height" Grid.Row="5" VerticalAlignment="Center" Grid.Column="1" Margin="5,0,0,0" Width="250"/>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Margin="0,0,4,0" Grid.Row="5" VerticalAlignment="Center" Text="Password" Style="{DynamicResource FormLabelStyle}"/>
                                </Grid>
                            </Border>
                        </Border>
                    </Border>
                </TabItem>
                <TabItem Header="Instances" Background="{DynamicResource ApplicationPanelBackgroundBrush}" Foreground="White">
                    <Border Style="{DynamicResource ApplicationOuterPanelBorderStyle}">
                        <Border Style="{DynamicResource ApplicationPanelBorderStyle}">
                            <Border Style="{DynamicResource ApplicationInnerPanelBorderStyle}">
                                <Grid>
                                    <rcl:BrowseModelInstance x:Name="browseModelInstance" DataContext="{Binding Path=MetaModel, Mode=TwoWay}" d:LayoutOverrides="Width, Height" Margin="0,10,0,0" />
                                </Grid>
                            </Border>
                        </Border>
                    </Border>

                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseLeftButtonUp">
                            <i:InvokeCommandAction Command="{Binding BrowseModelTabSelectedCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

                </TabItem>
                <TabItem Header="Model" IsEnabled="False" Background="{DynamicResource ApplicationPanelBackgroundBrush}" Foreground="White">
                    <Border Style="{DynamicResource ApplicationOuterPanelBorderStyle}">
                        <Border Style="{DynamicResource ApplicationPanelBorderStyle}">
                            <Border Style="{DynamicResource ApplicationInnerPanelBorderStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="0.031*"/>
                                        <RowDefinition Height="0.06*"/>
                                        <RowDefinition Height="0.06*"/>
                                        <RowDefinition/>
                                        <RowDefinition Height="0.05*"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="97.04"/>
                                        <ColumnDefinition Width="0.534*"/>
                                        <ColumnDefinition Width="0.466*"/>
                                        <ColumnDefinition Width="122.682"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBox x:Name="SearchInstanceName_tb1" TextWrapping="Wrap" Grid.Column="1" Margin="0" Grid.Row="1" VerticalAlignment="Center" Grid.ColumnSpan="2"/>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Margin="0,0,5,0" Grid.Row="1" VerticalAlignment="Center" Text="Instance name"/>
                                    <Button x:Name="SearchInstanceModel_bt" Content="Search" Grid.Column="3" Grid.Row="1" Height="25" Margin="5,-0.001,5,-0.55"/>
                                    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Row="2" Text="Path" VerticalAlignment="Center" Margin="0,0,5,0"/>
                                    <TextBox x:Name="InstancePath_tb" TextWrapping="Wrap" Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Grid.ColumnSpan="2"/>
                                    <Button x:Name="CopyInstancePathToClipboard_bt1" Content="Copy to clipboard" Grid.Column="3" Grid.Row="2" Height="25" Margin="5,-0.001,5,-0.551"/>
                                    <rcl:InstanceTree x:Name="InstanceModelTree" Grid.Row="3" d:LayoutOverrides="Width, Height" Grid.ColumnSpan="4"/>
                                </Grid>
                            </Border>
                        </Border>
                    </Border>
                </TabItem>
                <TabItem Header="Evaluate path" Background="{DynamicResource ApplicationPanelBackgroundBrush}" Foreground="White">
                    <Border Style="{DynamicResource ApplicationOuterPanelBorderStyle}">
                        <Border Style="{DynamicResource ApplicationPanelBorderStyle}">
                            <Border Style="{DynamicResource ApplicationInnerPanelBorderStyle}">
                                <Grid>
                                    <rcl:EvaluatePath x:Name="evaluatePath" DataContext="{Binding Path=MetaModel, Mode=TwoWay}" d:LayoutOverrides="Width, Height" Margin="0,10,0,0" />
                                </Grid>
                            </Border>
                        </Border>
                    </Border>

                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseLeftButtonUp">
                            <i:InvokeCommandAction Command="{Binding EvaluatePathTabSelectedCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

                </TabItem>
            </TabControl>
            <Border x:Name="ProjectInfoBorder" Grid.Column="1" Panel.ZIndex="4" Background="{DynamicResource TextBrush}" Style="{DynamicResource ApplicationOuterPanelBorderStyle}">
                <Border Style="{DynamicResource ApplicationPanelBorderStyle}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" MinHeight="28"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock TextWrapping="Wrap" Text="Provision Notebook info" HorizontalAlignment="Center" Grid.ColumnSpan="2" Foreground="{DynamicResource ControlBackgroundBrush}" d:LayoutOverrides="Height, GridBox" Margin="0,4,0,5" Style="{DynamicResource FormLabelStyle}" FontSize="16" FontWeight="Bold"/>
                        <Border Grid.Row="1" Style="{DynamicResource ApplicationInnerPanelBorderStyle}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="Auto" MinWidth="160.747"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="0"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Row="1" TextWrapping="Wrap" Text="Notebook name" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" Background="{x:Null}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold" />
                                <TextBlock Grid.Row="1" TextWrapping="Wrap" Text="{Binding ProjectInfo.NotebookName}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.999,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                                <TextBlock Grid.Row="3" TextWrapping="Wrap" Text="Last modification" VerticalAlignment="Center"  HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Background="{x:Null}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold"/>
                                <TextBlock Grid.Row="3" TextWrapping="Wrap" Text="{Binding ProjectInfo.LastModificationDate}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.999,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                                <TextBlock Grid.Row="4" TextWrapping="Wrap" Text="Imported" VerticalAlignment="Center"  HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Background="{x:Null}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold"/>
                                <TextBlock Grid.Row="4" TextWrapping="Wrap" Text="{Binding ProjectInfo.ImportedDate}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.998,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                                <TextBlock Grid.Row="5" TextWrapping="Wrap" Text="Nº images" VerticalAlignment="Center"  HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Background="{x:Null}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold"/>
                                <TextBlock Grid.Row="5" TextWrapping="Wrap" Text="{Binding ProjectInfo.ImagesCount}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.998,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                                <TextBlock Grid.Row="6" TextWrapping="Wrap" Text="Nº instances" VerticalAlignment="Center"  HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Background="{x:Null}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold"/>
                                <TextBlock Grid.Row="6" TextWrapping="Wrap" Text="{Binding ProjectInfo.InstancesCount}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.998,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                                <TextBlock Grid.Row="7" TextWrapping="Wrap" Text="Nº types" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Background="{x:Null}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold"/>
                                <TextBlock Grid.Row="7" TextWrapping="Wrap" Text="{Binding ProjectInfo.TypesCount}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.999,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                                <TextBlock Grid.Row="2" TextWrapping="Wrap" Text="Provision file version" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,3,0" Style="{DynamicResource FormLabelInverseStyle}" Background="{x:Null}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelSmallFontSize}" FontWeight="Bold"/>
                                <TextBlock Grid.Row="2" TextWrapping="Wrap" Text="{Binding ProjectInfo.ProvisionFileVersion}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2.999,0,0,0" Grid.Column="1" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource ControlBackgroundBrush}" FontSize="{DynamicResource FormLabelNormalFontSize}"/>
                            </Grid>
                        </Border>
                        <StackPanel HorizontalAlignment="Right" Orientation="Vertical" VerticalAlignment="Bottom" Margin="0,0,5,10" Grid.Row="1">
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                <CheckBox x:Name="importImagesCheckBox" Content="Import Images" VerticalAlignment="Center" Margin="0,0,5,0" IsChecked="True"/>
                                <Button x:Name="ImportNotebook_bt" Content="Import" VerticalAlignment="Center" Height="25" Margin="0" Width="100">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <i:InvokeCommandAction Command="{Binding ImportProvisionNotebookCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}">
                                                <i:InvokeCommandAction.CommandParameter>
                                                    <MultiBinding Converter="{StaticResource ImportNotebookMultiConverter}">
                                                        <Binding Mode="OneWay"/>
                                                        <Binding  ElementName="importImagesCheckBox" Path="IsChecked"/>
                                                    </MultiBinding>
                                                </i:InvokeCommandAction.CommandParameter>
                                            </i:InvokeCommandAction>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>
                            </StackPanel>
                            <Button x:Name="PublishProject_bt" Content="Publish Project" VerticalAlignment="Center" Width="100" HorizontalAlignment="Right" Margin="0,0,0,5" Height="25">
                            	<i:Interaction.Triggers>
                            		<i:EventTrigger EventName="Click">
                            			<i:InvokeCommandAction Command="{Binding PublishProjectCommmand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                            		</i:EventTrigger>
                            	</i:Interaction.Triggers>
                            </Button>
                            <Button Content="Report Problem" Padding="5" d:LayoutOverrides="Height" Height="25" Width="100" HorizontalAlignment="Right"/>
                        </StackPanel>
                    </Grid>
                </Border>
            </Border>
        </Grid>
    </Grid>
</UserControl>